﻿using Batman.Jianbei.Forum.Core.ChatRoom;
using Batman.Maintenance;
using Batman.Maintenance.DTO;
using Batman.Maintenance.DTO.ActionBar;
using Batman.Maintenance.DTO.Column;
using Batman.Maintenance.DTO.FormField;
using Batman.Maintenance.Enums;
using System.Collections.Generic;

namespace Batman.Jianbei.Forum.SimpleMaintenance
{
    public class MaskMaintenanceModel : MaintenanceModel<Mask>
    {
        public MaskMaintenanceModel()
        {
            this.HasKey(t => t.Id);

            #region 表格
            this.MainTable.TableReadAction("/Maintenance2/Read/");
            this.MainTable.HasImageColumn("头像", t => t.AvatarId, "avatar.url");
            this.MainTable.HasTextColumn("昵称", t => t.Nickname);
            this.MainTable.HasSwitchColumn("是否启用", t => t.IsDeleted, new SwitchColumn { ActiveValue = false, InActiveValue = true, ChangeAction = "/admin/maskAlbum/ChangeDeleted" });
            this.MainTable.HasSelection();
            this.MainTable.Include(t => t.Avatar);
            this.MainTable.Sort(t => t.CreateAt, OrderBy.Desc);

            #endregion

            #region 搜索栏

            this.SearchBar.AddField(t => t.Nickname, "搜索昵称", MaintenanceFormFieldType.Text, MaintenanceSearchBarCondition.包含);
            this.SearchBar.AddSelectionField(t => t.IsDeleted, "状态", new List<MaintenanceLabelValueDTO>
            {
                new MaintenanceLabelValueDTO{Label = "全部", Val = null},
                new MaintenanceLabelValueDTO{Label = "启用的", Val = 0},
                new MaintenanceLabelValueDTO{Label = "禁用的", Val = 1}
            }, 0);

            #endregion

            #region 动作栏

            this.ActionBar.HasAction(new MaintenceAction("批量禁用", "Admin/MaskAlbum/SetDeleted", "post", true, "删除后无法恢复 确认删除吗？"));
            this.ActionBar.HasAction(new MaintenceAction("批量启用", "Admin/MaskAlbum/SetUnDeleted", "post", false, string.Empty));

            #endregion

            #region 新建表单

            this.CreateForm.SumitAction("/admin/MaskAlbum/addMask")
                           .HasFormField(t => t.Nickname, new MaintenanceTextFormField { Label = "昵称" })
                           .HasFormField(t => t.AvatarId, new MaintenanImageFormField { Label = "头像", Action = "/chatroom/MaskAlbum/UploadMaskImage" });

            #endregion

            #region 跟新表单

            this.UpdateForm.SumitAction("/admin/MaskAlbum/UpdateMask");
            this.UpdateForm.HasFormField(t => t.Id, new MaintenanceTextFormField { Label = "编号", Hide = true });
            this.UpdateForm.HasFormField(t => t.AvatarId, new MaintenanImageFormField { Label = "头像", MapField = "avatar.url", Action = "/chatroom/MaskAlbum/UploadMaskImage" });
            this.UpdateForm.HasFormField(t => t.Nickname, new MaintenanceTextFormField { Label = "昵称" });
            this.UpdateForm.UpdateFormHasReadAction("/admin/MaskAlbum/GetMask");

            #endregion
        }
    }
}
